﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WindowsHelper;

namespace GlobalHooksTest
{
    public partial class ReorderPinnedItems : Form
    {
        public ReorderPinnedItems()
        {
            InitializeComponent();
        }
        public SysImageList syssmal = new SysImageList(SysImageListSize.smallIcons);
        private void ReorderPinnedItems_Load(object sender, EventArgs e)
        {
            csSbar.Close();
            csSbar.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + "\"" + Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\SbarDB.mdb" + "\"";//""E:\Personal Projects\C#\Global Hook\GlobalHooksTest\bin\Debug\SbarDB.mdb"
            csSbar.Open();
            pinnedTableAdapter1.Connection = csSbar;
            taskbarPinnedTableAdapter1.Connection = csSbar;

            taskbarPinnedTableAdapter1.Fill(ds1.TaskbarPinned);
            SysImageListHelper.SetListViewImageList(listViewEx1,syssmal,false);
            foreach (DataRow dr in ds1.TaskbarPinned.Rows)
            {
                ListViewItem lvi = new ListViewItem(dr["EXE_NAME"].ToString());
                lvi.ImageIndex = syssmal.IconIndex(dr["EXE_PATH"].ToString());
                lvi.SubItems.Add(dr["EXE_PATH"].ToString());
                listViewEx1.Items.Add(lvi);
            }
        }

        private void ReorderPinnedItems_FormClosing(object sender, FormClosingEventArgs e)
        {
            taskbarPinnedTableAdapter1.DeleteAll();
            taskbarPinnedTableAdapter1.Update(ds1.TaskbarPinned);
            ds1.AcceptChanges();

            foreach (ListViewItem li in listViewEx1.Items)
            {
                taskbarPinnedTableAdapter1.Insert(li.Text, li.SubItems[1].Text, li.Index + 1);
                taskbarPinnedTableAdapter1.Update(ds1.TaskbarPinned);
                ds1.AcceptChanges();
            }
        }
    }
}
